import { getLinesOfOverlayWithFilter } from "../../widgets/line-plot/drawLine"
import { drawAirLine } from "../../widgets/model-manage/map"
import { toRaw } from "vue"
import { viewerId, rightViewerId } from "../../components/de-work/map"

/**
 * 图层的右键菜单配置
 */
export default {
  [viewerId]: {
    // layer id 为 equipLayer 的图层菜单
    equipPlotLayer: (layer, options) => {
      const { context } = options
      return [
        {
          label: "开始编辑对象",
          callback: (e) => {
            console.log("开始编辑对象--", e)
            layer.startEditing(e.overlay)
          },
          show: (e) => {
            return e.overlay?.hasEdit && !e.overlay?.isEditing
          },
          context: context || this
        },
        {
          label: "绘制航迹",
          callback: (pickInfo) => {
            console.log("绘制航迹-", pickInfo)
            drawAirLine(pickInfo)
          },
          show: (e) => {
            return !getLinesOfOverlayWithFilter(e.overlay, (overlay, line) => {
              return line && line.attr?.equipIds?.includes(overlay.overlayId) && line.attr.type === "airline"
            }).length
          },
          context: context || this
        },
        {
          label: "结束编辑对象",
          callback: (e) => {
            layer.stopEditing()
          },
          show: (e) => {
            return e.overlay?.hasEdit && e.overlay?.isEditing
          },
          context: context || this
        },
        {
          label: "删除对象",
          callback: (e) => {
            layer.removeOverlay(e.overlay)
          },
          show: (e) => {
            return e.overlay?.hasEdit && !e.overlay?.isEditing
          },
          context: context || this
        }
      ]
    },
    actionPlotLayer: (layer, options) => {
      return [{
        label: "删除对象",
        callback: (e) => {
          layer.removeOverlay(e.overlay)
        },
        show: (e) => {
          return e.overlay?.hasEdit && !e.overlay?.isEditing
        },
        context: this
      }]
    },
    effectsLayer: () => {
      return [
        {
          label: "编辑特效",
          callback: (e) => {
            e?.overlay && window?.$showEditor({
              name: "overlay-editor",
              data: {
                overlay: toRaw(e.overlay)
              }
            })
          },
          show: (e) => {
            return true
          }
        }
      ]
    }
  }
}
